/******************************************************************************
*
* This file is part of FreeTrack (http://code.google.com/p/qtfreetrack).
* BY Willy Gardiol (willy@gardiol.org)
*
* FreeTrack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FreeTrack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar.  If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/

#ifndef WORKERLOADGPX_H
#define WORKERLOADGPX_H

#include <QXmlStreamReader>

#include "workerprocess.h"
#include "gps_track.h"

class WorkerLoadGpx : public WorkerProcess
{
    Q_OBJECT
public:
    explicit WorkerLoadGpx( const QString&, GPS_track*, const QString &);
    explicit WorkerLoadGpx(QByteArray&, GPS_track*, const QString& );

    ~WorkerLoadGpx();

protected:
    bool do_stuff();

private:
    QXmlStreamReader* reader;
    QFile file;

    GPS_track* track;

    void readWaypoint(double, double);
    void readTrk();
    void readTrkSeg(GPS_leg*);
    void readPoint( GPS_leg*, double, double );
    void readRte();

    bool updateWaypoints();
    bool updateLegs();
    bool updatePoints();

    int n_points;
    int n_legs;
    int n_waypoints;

    bool readNextNode(QString&, QXmlStreamAttributes& );
    bool readNextNode(const QString&, QString&, QXmlStreamAttributes& );
    void readNodeData( QString& );
    void readNodeData( double& );
    void readNodeData( int& );
    void readNodeData( QDateTime& );

    QStringList nodeStack;
    void readBounds(const QXmlStreamAttributes&);
    QColor readColor(const QXmlStreamAttributes&);

    QString saved_string;

};

#endif // WORKERLOADGPX_H
